// pages/account/account.js
var common = require('../../common.js');
var app = getApp();
Page({
  data: {},
  onLoad: function () {
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      console.log(userInfo)
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })
    wx.showToast({
        title: 'Loading',
        icon: 'loading',
    })
    common.cRequst({
      url: 'http://'+ common.serveIp +'/user.php?c=wapuser&a=waplogin',
      data: {
        "country_num": "86",
        "password": "abc123456",
        "phone": "18038090351",
        "session_id": null,
        "version": "app"
      },
      method:"Post",
      success: function (res) {
        console.log(res);
        that.setData({
          user: res.data
        })
        wx.setStorage({
          key: "user",
          data: res.data
        })
        wx.showToast({
          title: '登录成功',
          icon: 'success',
          mask:true,
          duration: 1500
        })
      }
    });
  },
  gocertify: function () {
    wx.showToast({
        title: 'Loading',
        icon: 'loading',
    })
    wx.getStorage({
      key: 'user',
      success: function (res) {
        console.log(res)
        common.cRequst({
          url: 'http://'+ common.serveIp +'/user.php?c=dp_authentication&a=approveInfo',
          data: {
            "session_id": res.data.session_id,
            "type": "3",
            "version": "app"
          },
          method: "Post",
          success: function (data) {
            console.log(data.data);
            if (!data.data) {
              wx.navigateTo({
                url: "/pages/account/namecheck/uncheck"
              })
            }else{
              wx.navigateTo({
                url:"/pages/account/namecheck/namecheck"
              })
            }
          }
        })
      }
    })
  }
})